﻿using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class CameraController : MonoBehaviour
{
/*    // 跟随目标
    public Transform follow;
    // 偏移量
    private Vector3 offset;*/

    private bool stopFollow =false;

    private Vector3[] moveTargetInitPos;

    public Transform rocketHeadTrans;

    // Start is called before the first frame update
    void Start()
    {
        // 偏移量= 火箭的位置 - 当前摄像机的位置
        // offset = follow.position - transform.position;
        
         moveTargetInitPos = new Vector3[] {new Vector3(-0.04f, 1.7f,-3.5f),new Vector3(0.25f,3.3f,-4.33f) };

    }

    // 加长火箭修改镜头位置
    public void ChangeCameraPos()
    {
        if (PlayerManager.instance.rocketLength >= 8)
        {
            transform.localPosition = new Vector3(-0.41f, 3.17f, -4f);
        }
        else
        {
            transform.localPosition = new Vector3(-0.19f, 1.22f, -3.09f);
        }
    }

    public void MoveCamera(bool stopFollow = false)
    {
        if (!stopFollow)
        {
            transform.DOLocalMove(transform.localPosition + new Vector3(0.0f, 0.1f,0f), 1);
            // 沿着Z轴旋转一个角度
            transform.DOLocalRotate(transform.eulerAngles + new Vector3(0, 0, 5f), 1);
        }
        else
        {
            this.stopFollow = stopFollow;
            transform.SetParent(null);
            DOTween.KillAll();
        }
    }

    // Update is called once per frame
    void LateUpdate()
    {
        // Debug.Log(offset);
        // 跟随 摄像机才跟着跟随对象移动
        /*        if (!stopFollow)
                {
                    // 让摄像机的位置 = 火箭的位置 - 偏移量
                    transform.position = follow.position - offset;
                }
                // 摄像机对着跟随目标
                transform.LookAt(follow);*/

        if (stopFollow)
        {
            transform.LookAt(rocketHeadTrans);
        }
    }

/*    public void GetNewOffsetAndFollowTarget(Transform newTargetTrans, bool stopFollow = false)
    {
        follow = newTargetTrans;
        this.stopFollow = stopFollow;
        offset = follow.position - transform.position;
    }*/
}
